/*
 * DuList.h
 *
 *  Created on: 2011-5-2
 *      Author: william nie
 */

#include<stdio.h>
#include<stdlib.h>
#include"datadef.h"

#ifndef DULIST_H_
#define DULIST_H_

typedef struct DuListNod {
	int data;
	struct DuListNod *prior;
	struct DuListNod *next;
} DLElemType;

typedef struct {
	DLElemType *head;
	int length;
	int listsize;
} DuList;

//����Ƚ�ԭ����ָ��
typedef BOOL (*Compare)(int elem1,int elem2);

//ListTraverse��visit�Ķ���
typedef BOOL (*Visit)(DLElemType *elem);

/*
 * ��׼�����Ա������
 */

//����һ���յ����Ա�list
Status InitDuList(DuList **duListP);

//������Ա�list
Status DestoryDuList(DuList **duListP);

//�����Ա�list��գ���Ϊ�ձ�
Status ClearDuList(DuList *duList);

//������Ա��Ƿ�Ϊ��
BOOL DuListEmpty(DuList *duList);

//�������Ա�list�ı?
int DuListLength(DuList *duList);

//������Ա�list��λ��Ϊloc��Ԫ��
DLElemType* GetDuElem(DuList *duList, int loc);

//����list�е�һ����elemToCompareԪ������rule����ĵ�Ԫ�ص�λ��
int LocateDuElem(DuList *duList, int elemToCompare, Compare rule);

//����list����Ԫ��elem��ֱ��ǰ��
DLElemType* PriorDuElem(DuList *duList, int elem);

//����list����Ԫ��elem��ֱ�Ӻ���
DLElemType* NextDuElem(DuList *duList, int elem);

//��list��λ��Ϊloc��Ԫ��֮ǰ����һ����Ԫ��elem������ʹ�?����1
Status DuListInsert(DuList *duList, int loc, int elem);

//ɾ��list��λ��Ϊloc��Ԫ�أ����ҷ��ظñ�ɾ���Ԫ�أ����ʹ������1
Status DuListDelete(DuList *duList, int loc);

//��list��ÿ��Ԫ�ص���visit�����visit����ʧ�ܣ���������ʧ��
BOOL DuListTraverse(DuList *duList, Visit visit);

/*
 * ���ӵ����Ա����
 */

//Ϊ���Ա���д����
Status FillDuList(DuList *duList);

//��ӡ���Ա�ȫ������
Status PrintDuList(DuList *duList);

//�͵ط�ת������
Status ReverseDuList(DuList *duList);

//��ӡ���Ա�Ԫ��
Status PrintDuListElem(DuList *duList);

//ȱʡ�ıȽϹ���
BOOL DuDefaultCompare(int elem1, int elem2);

//ȱʡ�ı������
BOOL DuDefaultVisit(DLElemType *elem);

#endif /* DULIST_H_ */
